package com.wsdcd.zlg.util;

import java.util.Calendar;
import java.util.Date;

public class AboutTime {
	/*
	 * 从1970年1月1日到今天有多少天
	 */
	public static long getDayFromZero(){
		//获取当前系统时间的毫秒数
		long nowTime = System.currentTimeMillis();
		//一天有多少毫秒
		long dayMillis = 1000*60*60*24;
		
		long day = nowTime/dayMillis;
		return day;
	}

	/*
	 * 获取当前时间是星期几
	 */
	public static int getWeek(){
		int weekDaysint[] = {7,1,2,3,4,5,6};
        Calendar calendar=Calendar.getInstance();
        int nowWeek = weekDaysint[calendar.get(Calendar.DAY_OF_WEEK)-1];
		return nowWeek;
	}
	
	/*
	 * 获取当前时间 返回Date类型年月日
	 */
	public static Date getYearMonthDay(){
		Calendar calendar = Calendar.getInstance();
//		int year = calendar.get(Calendar.YEAR);
//		int month = calendar.get((Calendar.MONTH)+1);
//		int day = calendar.get(Calendar.DATE);
//		System.out.println( year );
//		System.out.println( month );
//		System.out.println( day );
		
		Date date=calendar.getTime();
		return date;
	}
	
	/*
	 * 传递一个参数 返回值为 当前日期减去参数日期的date类型数据
	 */
	public static Date nowDateDecreaseDay(int day){
		//获取当前日期
		Date date = new Date();
		//得到日历类实例化对象
		Calendar calendar = Calendar.getInstance(); 
		//设置日期
		calendar.setTime(date);
		calendar.add(Calendar.DATE, -day);
		Date dateDec = calendar.getTime();
		return dateDec;
	}
	
}
